LeaveBillManagerView = Ext.extend(Ext.Panel, {
    constructor : function(a) {
        Ext.applyIf(this, a);
        var all=this.initUIComponents();
        LeaveBillManagerView.superclass.constructor.call(this, {
            id : "LeaveBillManagerView",
            region : "center",
            layout : "border",
            border : false,
            iconCls : "menu-position",
            items : [all.yearGridPanel]
        });
    },
    initUIComponents : function() {
         var yearGridComponents=new creategridview({
            topbar : {
                inputFormName : 'LeaveBillManagerForm',
                hidden: false,
                topbarAdd:{
                    hidden:false
                },
                topbarDel:{
                    hidden:true
                }
            },
            search : {
                items : [ ]
            },
            grid : {
                title : "请假单信息列表",
                rowdblclick:true,
                listUrl : __ctxPath + "/bpmndemo/listLeaveBill.do",
                fields : [ "id", 'userId','name','days', "reason","status"],
                columns : [ {
                    header : "id",
                    dataIndex : "id",
                    hidden :true
                },  {
                    header : "请假人用户名",
                    dataIndex : "userId",
                    hidden : true,
                    width : 70
                }, {
                    header : "请假人姓名",
                    dataIndex : "name",
                    width : 70
                }, {
                    header : "请假天数",
                    dataIndex : "days",
                    width : 30
                }, {
                    header : "请假原因",
                    dataIndex : "reason",
                    width : 100
                },{
                    header:"状态",
                    dataIndex:"status",
                    width:50,
                    renderer: function(v){
                        if(v==1){
                            return "未审核"
                        }else
                        if(v==2){
                            return "审核中"
                        }else
                        if(v==3){
                            return "审核完成"
                        }
                    }
                },{
                    header:"操作",
                    dataIndex:"status",
                    width:50,
                    renderer: function(status, i, g, m, h){
                        var k = "";
                        if(status==1){
                            k += '<a href="javascript:void(0)" onclick=\'LeaveBillManagerView.liuchengkaishi('
                                + g.data.id + ')\'>申请请假</button>'; 
                        }else{
                            k += '<a href="javascript:void(0)" onclick=\'LeaveBillManagerView.chakanjindu('
                                + g.data.id  + ')\'>查看审批记录</a>';
                        }
                       return k;
                    }
                },{
                    header:"管理",
                    dataIndex:"status",
                    width:70,
                    renderer : function(status, i, g, m, h) {
                        var k = "";
                        if(status==1){
                            k += '　<button title="编辑" value="" class="btn-edit" onclick=\'LeaveBillManagerView.bianji('
                                + g.data.id  + ')\'></button>';
                            k += '　<button title="删除" value="" class="btn-delete" onclick=\'LeaveBillManagerView.shanchu('
                                + g.data.id  + ')\'></button>';
                            
                        }else if(status==3){
                            k += '　<button title="删除" value="" class="btn-delete" onclick=\'LeaveBillManagerView.shanchu('
                                + g.data.id  + ')\'></button>';
                        }
                        return k;
                    }
                }]
                
            }
        });
        return yearGridComponents;
    }
});
LeaveBillManagerView.chakanjindu=function(leaveBillId){
    Ext.Ajax.request({
        url: __ctxPath + "/bpmndemo/findInstanceIdByBusinessIdLeaveBill.do",
        params: { businessId: leaveBillId },
        success: function(resp,thiz){
           var rsponObj= Ext.decode(resp.responseText);
           if(rsponObj.success){
               var instanceId=rsponObj.result;
               if(instanceId){
                   var cfg={
                           businessId :  leaveBillId,
                           instanceId :  instanceId,
                           isShow : true
                         }
                        new LeavBillAuditFormWindow(cfg).show(); 
               }
           }else{
               //Ext.ux.Toast.msg("流程启动失败：",rsponObj.msg)
           }
        },
        failure: function(){
            Ext.ux.Toast.msg("操作提示：","请求失败！")
        }
     });
}
LeaveBillManagerView.liuchengkaishi=function(leaveBillId){
    Ext.Ajax.request({
        url: __ctxPath + "/bpmndemo/startProcessLeaveBill.do",
        params: { businessId: leaveBillId },
        success: function(resp,thiz){
           var rsponObj= Ext.decode(resp.responseText);
           if(rsponObj.success){
               Ext.ux.Toast.msg("操作提示：","流程启动成功！")
               Ext.getCmp("LeaveBillManagerView").items.items[0].store.reload();
           }else{
               Ext.ux.Toast.msg("流程启动失败：",rsponObj.msg)
           }
        },
        failure: function(){
            Ext.ux.Toast.msg("操作提示：","请求失败！")
        }
     });

}